home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2005 March / Gamestar_71_2005-03_dvd.iso / Dema / willofsteel_demo.exe / {app} / Data / Shaders / default14sf.fx < prev    next >
Text File  |  2004-10-23  |  15KB  |  558 lines

  1. float4x4 WorldViewProjection;
  2. float4x4 ShadowViewProjection;
  3. float4x4 TextureMatrix;
  4. float4x4 WorldMatrix;
  5. float4x4 ViewIT;
  6.  
  7. texture AlphaTexture;
  8. texture DiffuseTexture;
  9. texture ShadowTexture;
  10. texture CloudsTexture;
  11. texture FogOfWar;
  12. texture BurnedTexture;
  13. float4  BurnFactor     = { 0.4, 0.4, 0.4, 0.4 };
  14.  
  15. float3 LightDirection = { 0.0f, 0.0f, 0.0f };
  16. float3 SunColor       = { 1., 0.86, .70  };
  17. float3 Ambient        = { 0.24, 0.12, 0.04 };
  18. float4 FogScale          = { 0.001953125, 0.001953125, 0.001953125, 0.001953125 };    
  19. float4 ZBias          = { 0.0, 0.0, 0.0, -0.004 };
  20. float4 ShadowOffset;
  21. float4 CloudUVShift    = { 0.0, 0.0, 0.0, 0.0 };
  22. float4 CloudScale      = { 0.01, 0.01, 0.01, 0.01 };
  23. float4 BlinkFactor     = { 0.0, 0.0, 0.0, 0.0 };
  24.  
  25. technique Technique0
  26. {
  27.     pass Pass0
  28.     {
  29.         Texture[0]               = (DiffuseTexture);
  30.         Texture[1]               = (ShadowTexture);
  31.         Texture[2]               = (FogOfWar);
  32.  
  33.         VertexShaderConstant[0]   = <WorldViewProjection>;
  34.         VertexShaderConstant[4]   = <ShadowViewProjection>;
  35.         VertexShaderConstant[8]   = <TextureMatrix>;
  36.         VertexShaderConstant[12]  = <WorldMatrix>;
  37.         VertexShaderConstant[26]  = <BlinkFactor>;
  38.         VertexShaderConstant[27]  = <FogScale>;
  39.         VertexShaderConstant[30]  = <LightDirection>;
  40.         VertexShaderConstant[31]  = <ZBias>;
  41.         VertexShaderConstant[32]  = <SunColor>;
  42.  
  43.         ALPHABLENDENABLE = FALSE;
  44.         ALPHATESTENABLE  = FALSE;
  45.  
  46.         VertexShader =
  47.         decl
  48.         {
  49.             stream 0;
  50.             float v0[3];       // Position
  51.             float v3[3];       // Normal
  52.             float v6[2];       // Texture coord1
  53.         }
  54.         asm
  55.         {
  56.             //-----------------------------------------------------------------------------
  57.             // Vertex shader for rendering shadows
  58.             // c0..3    - WVP
  59.             // c4..7    - world to light proj x-form
  60.             // c8..11    - shadow proj x-form
  61.             // c12.13    - View matrix
  62.             // c29        - Cloud UV shift
  63.             // c30        - light direction
  64.             // c31        - Z Bias vector
  65.             //-----------------------------------------------------------------------------
  66.             vs_1_1
  67.  
  68.             dcl_position v0
  69.             dcl_normal v3
  70.             dcl_texcoord0  v6
  71.  
  72.             m4x4  oPos, v0, c0        // Transform and output position
  73.             m4x4  r0, v0, c12        // Transform and output position
  74.             mul   r0, r0, c27
  75.             mov   oT2.x, r0.x       // Fog of war texture coords
  76.             mov   oT2.y, r0.z       // Fog of war texture coords
  77.             
  78.             mov   oT0, v6           // Copy texture coords
  79.             dp4   oT1.x, v0, c8     // Shadow map projection
  80.             dp4   oT1.y, v0, c9
  81.  
  82.             dp3   r0, -v3, c30      // Diffuse //Lighting
  83.             mul   r0, r0, c32
  84.             add   oD0, r0, c26
  85.  
  86.             dp4   r0, v0, c6        // Depth in light space
  87.             add   oT3.x, r0, c31.w  // Add Bias
  88.         };
  89.  
  90.        
  91.         PixelShaderConstant[17]  = <Ambient>;
  92.  
  93.         PixelShader =
  94.         asm
  95.         {
  96.             ps_1_4
  97.               def c0, 1, 1, 1, 1
  98.             def c1, 0.0, 0.0, 0.0, 0
  99.             
  100.             dcl t0.xyzw
  101.             dcl t1.xy
  102.             dcl t2.xy
  103.             dcl t3.x
  104.             dcl v0.rgba
  105.  
  106.             dcl_2d s0
  107.             dcl_2d s1
  108.             dcl_2d s2
  109.             
  110.             texld   r10, t1, s1            // Z - semplovani Z projektovane teksture
  111.             sub     r9.r, r10.r, t3.x   // razlika Z vrednosti
  112.  
  113.             mov     r1, c1              // r1 - 1, 1, 1, 1
  114.             cmp     r10, r9.r, c0, r1   //-r9.r//, r1
  115.  
  116.             //mov     r0, t0
  117.             frc     r0, t0
  118.             texld   r1, r0, s0
  119.             mad     r0, r10, v0, c17    // (shadow * diffuse) + ambient
  120.             mul     r0, r1, r0
  121.  
  122.             texld   r2, t2, s2
  123.             mul     r0, r2, r0
  124.             
  125.             mov     oC0, r0                // output
  126.         };
  127.     }
  128. }
  129.  
  130.  
  131. // rendering u shadow mapu
  132. technique Technique1
  133. {
  134.     pass Pass0
  135.     {
  136.         Texture[0]               = (DiffuseTexture);
  137.  
  138.         VertexShaderConstant[0]   = <WorldViewProjection>;
  139.         VertexShaderConstant[31]  = <ZBias>;
  140.  
  141.         ALPHABLENDENABLE = FALSE;
  142.         ALPHATESTENABLE  = FALSE;
  143.         
  144.         VertexShader =
  145.         decl
  146.         {
  147.             stream 0;
  148.             float v0[3];       // Position
  149.             float v3[3];       // Normal
  150.             float v6[2];       // Texture coord1
  151.         }
  152.         asm
  153.         {
  154.             //-----------------------------------------------------------------------------
  155.             // Vertex shader for rendering shadows
  156.             // c0..3    - WVP
  157.             // c4..7    - world to light proj x-form
  158.             // c8..11    - shadow proj x-form
  159.             // c12.13    - View matrix
  160.             // c30        - light direction
  161.             // c31        - Z Bias vector
  162.             //-----------------------------------------------------------------------------
  163.             vs_1_1
  164.  
  165.             dcl_position v0
  166.             dcl_texcoord0  v6
  167.         
  168.             m4x4  r0, v0, c0   // Transform position
  169.             mov   oPos, r0     // Output position
  170.             mov   oT0, v6
  171.             mov   oT1.x, r0.z  // Output depth
  172.             
  173.         };
  174.         
  175.         PixelShader =
  176.         asm
  177.         {
  178.             ps_1_4
  179.  
  180.             dcl        t0.xyzw
  181.             dcl        t1.x
  182.             dcl_2d  s0
  183.             
  184.             mov        r0, t1.x
  185.             mov        oC0, r0
  186.         };
  187.     }
  188. }
  189.  
  190.  
  191. technique Technique2
  192. {
  193.     pass Pass0
  194.     {
  195.         Texture[0]               = (DiffuseTexture);
  196.         Texture[1]               = (ShadowTexture);
  197.         Texture[2]               = (FogOfWar);
  198.  
  199.         VertexShaderConstant[0]   = <WorldViewProjection>;
  200.         VertexShaderConstant[4]   = <ShadowViewProjection>;
  201.         VertexShaderConstant[8]   = <TextureMatrix>;
  202.         VertexShaderConstant[12]  = <WorldMatrix>;
  203.         VertexShaderConstant[26]  = <BlinkFactor>;
  204.         VertexShaderConstant[27]  = <FogScale>;
  205.         VertexShaderConstant[30]  = <LightDirection>;
  206.         VertexShaderConstant[31]  = <ZBias>;
  207.         VertexShaderConstant[32]  = <SunColor>;
  208.  
  209.         ALPHABLENDENABLE = TRUE;
  210.         SRCBLEND         = SRCALPHA;
  211.         DESTBLEND        = INVSRCALPHA;
  212.         ALPHATESTENABLE  = TRUE;
  213.         ALPHAFUNC        = GREATER;
  214.         ALPHAREF         = 1;
  215.  
  216.         VertexShader =
  217.         decl
  218.         {
  219.             stream 0;
  220.             float v0[3];       // Position
  221.             float v3[3];       // Normal
  222.             float v6[2];       // Texture coord1
  223.         }
  224.         asm
  225.         {
  226.             //-----------------------------------------------------------------------------
  227.             // Vertex shader for rendering shadows
  228.             // c0..3    - WVP
  229.             // c4..7    - world to light proj x-form
  230.             // c8..11    - shadow proj x-form
  231.             // c12.13    - View matrix
  232.             // c30        - light direction
  233.             // c31        - Z Bias vector
  234.             //-----------------------------------------------------------------------------
  235.             vs_1_1
  236.  
  237.             dcl_position v0
  238.             dcl_normal v3
  239.             dcl_texcoord0  v6
  240.  
  241.             m4x4  oPos, v0, c0        // Transform and output position
  242.             m4x4  r0, v0, c12        // Transform and output position
  243.             mul   r0, r0, c27
  244.             mov   oT2.x, r0.x       // Fog of war texture coords
  245.             mov   oT2.y, r0.z       // Fog of war texture coords
  246.  
  247.  
  248.             mov   oT0, v6           // Copy texture coords
  249.             dp4   oT1.x, v0, c8     // Shadow map projection
  250.             dp4   oT1.y, v0, c9
  251.  
  252.             dp3   r0, -v3, c30      // Diffuse //Lighting
  253.             mul   r0, r0, c32
  254.             add   oD0, r0, c26
  255.  
  256.             dp4   r0, v0, c6        // Depth in light space
  257.             add   oT3.x, r0, c31.w  // Add Bias
  258.         };
  259.         
  260.         PixelShaderConstant[17]  = <Ambient>;
  261.  
  262.         PixelShader =
  263.         asm
  264.         {
  265.             ps_1_4
  266.               def c0, 1, 1, 1, 1
  267.             def c1, 0.0, 0.0, 0.0, 0
  268.             
  269.             def c2, 0., 0., 0., .0        // zero
  270.             def c3, 1.0, 1.0, 1.0, 1.0    // fog color
  271.             def c18, 10., 0., 0.1, 1.0        // ambient color
  272.  
  273.             dcl t0.xyzw
  274.             dcl t1.xy
  275.             dcl t2.xy
  276.             dcl t3.x
  277.             dcl v0.rgba
  278.  
  279.             dcl_2d s0
  280.             dcl_2d s1
  281.             dcl_2d s2
  282.             
  283.             texld   r10, t1, s1            // Z - semplovani Z projektovane teksture
  284.             sub     r9.r, r10.r, t3.x   // razlika Z vrednosti
  285.  
  286.             mov     r1, c1              // r1 - 1, 1, 1, 1
  287.             cmp     r10, r9.r, c0, r1   //-r9.r//, r1
  288.  
  289.             //mov     r0, t0
  290.             frc     r0, t0
  291.             texld   r1, r0, s0
  292.             mad     r0, r10, v0, c17    // (shadow * diffuse) + ambient
  293.             mul     r0, r1, r0
  294.  
  295.             texld   r2, t2, s2
  296.             mul     r0, r2, r0
  297.  
  298.             mov     r0.a, r1.a
  299.  
  300.             mov     oC0, r0                // output
  301.         };
  302.     }
  303. }
  304.  
  305.  
  306. // rendering u shadow mapu
  307. technique Technique3
  308. {
  309.     pass Pass0
  310.     {
  311.         Texture[0]               = (DiffuseTexture);
  312.  
  313.         VertexShaderConstant[0]   = <WorldViewProjection>;
  314.         VertexShaderConstant[31]  = <ZBias>;
  315.  
  316.         ALPHABLENDENABLE = FALSE;
  317.         ALPHATESTENABLE  = FALSE;
  318.  
  319.         VertexShader =
  320.         decl
  321.         {
  322.             stream 0;
  323.             float v0[3];       // Position
  324.             float v3[3];       // Normal
  325.             float v6[2];       // Texture coord1
  326.         }
  327.         asm
  328.         {
  329.             //-----------------------------------------------------------------------------
  330.             // Vertex shader for rendering shadows
  331.             // c0..3    - WVP
  332.             // c4..7    - world to light proj x-form
  333.             // c8..11    - shadow proj x-form
  334.             // c12.13    - View matrix
  335.             // c30        - light direction
  336.             // c31        - Z Bias vector
  337.             //-----------------------------------------------------------------------------
  338.             vs_1_1
  339.  
  340.             dcl_position   v0
  341.             dcl_texcoord0  v6
  342.         
  343.             m4x4  r0, v0, c0   // Transform position
  344.             mov   oPos, r0     // Output position
  345.             mov   oT0, v6
  346.             mov   oT1.x, r0.z  // Output depth
  347.             
  348.         };
  349.         
  350.         PixelShader =
  351.         asm
  352.         {
  353.             ps_1_4
  354.  
  355.             def c0, 0.5, 1, 1, 1
  356.             dcl        t0.xyzw
  357.             dcl        t1.x
  358.             dcl_2d  s0
  359.             
  360.             texld   r1, t0, s0
  361.             sub     r0, r1.w, c0.x        // simulate alpha test
  362.             texkill r0
  363.             mov        r0, t1.x
  364.             mov        oC0, r0
  365.         };
  366.     }
  367. }
  368.  
  369. technique Technique4
  370. {
  371.     pass Pass0
  372.     {
  373.         Texture[0]               = (DiffuseTexture);
  374.         Texture[1]               = (ShadowTexture);
  375.         Texture[2]               = (FogOfWar);
  376.         Texture[3]               = (BurnedTexture);
  377.  
  378.         VertexShaderConstant[0]   = <WorldViewProjection>;
  379.         VertexShaderConstant[4]   = <ShadowViewProjection>;
  380.         VertexShaderConstant[8]   = <TextureMatrix>;
  381.         VertexShaderConstant[12]  = <WorldMatrix>;
  382.         VertexShaderConstant[26]  = <BlinkFactor>;
  383.         VertexShaderConstant[27]  = <FogScale>;
  384.         VertexShaderConstant[30]  = <LightDirection>;
  385.         VertexShaderConstant[31]  = <ZBias>;
  386.         VertexShaderConstant[32]  = <SunColor>;
  387.  
  388.         ALPHABLENDENABLE = TRUE;
  389.         SRCBLEND         = SRCALPHA;
  390.         DESTBLEND        = INVSRCALPHA;
  391.         ALPHATESTENABLE  = TRUE;
  392.         ALPHAFUNC        = GREATER;
  393.         ALPHAREF         = 1;
  394.  
  395.         VertexShader =
  396.         decl
  397.         {
  398.             stream 0;
  399.             float v0[3];       // Position
  400.             float v3[3];       // Normal
  401.             float v6[2];       // Texture coord1
  402.         }
  403.         asm
  404.         {
  405.             //-----------------------------------------------------------------------------
  406.             // Vertex shader for rendering shadows
  407.             // c0..3    - WVP
  408.             // c4..7    - world to light proj x-form
  409.             // c8..11    - shadow proj x-form
  410.             // c12.13    - View matrix
  411.             // c30        - light direction
  412.             // c31        - Z Bias vector
  413.             //-----------------------------------------------------------------------------
  414.             vs_1_1
  415.  
  416.             dcl_position v0
  417.             dcl_normal v3
  418.             dcl_texcoord0  v6
  419.  
  420.             m4x4  oPos, v0, c0        // Transform and output position
  421.             m4x4  r0, v0, c12        // Transform and output position
  422.             mul   r0, r0, c27
  423.             mov   oT2.x, r0.x       // Fog of war texture coords
  424.             mov   oT2.y, r0.z       // Fog of war texture coords
  425.  
  426.  
  427.             mov   oT0, v6           // Copy texture coords
  428.             mov   oT4, v6           // Copy texture coords
  429.             dp4   oT1.x, v0, c8     // Shadow map projection
  430.             dp4   oT1.y, v0, c9
  431.  
  432.             dp3   r0, -v3, c30      // Diffuse //Lighting
  433.             mul   r0, r0, c32
  434.             add   oD0, r0, c26
  435.  
  436.             dp4   r0, v0, c6        // Depth in light space
  437.             add   oT3.x, r0, c31.w  // Add Bias
  438.         };
  439.         
  440.         PixelShaderConstant[16]  = <BurnFactor>;
  441.         PixelShaderConstant[17]  = <Ambient>;
  442.  
  443.         PixelShader =
  444.         asm
  445.         {
  446.             ps_1_4
  447.               def c0, 1, 1, 1, 1
  448.             def c1, 0.0, 0.0, 0.0, 0
  449.             
  450.             def c2, 0., 0., 0., .0        // zero
  451.             def c3, 1.0, 1.0, 1.0, 1.0    // fog color
  452.             def c18, 10., 0., 0.1, 1.0        // ambient color
  453.  
  454.             dcl t0.xy
  455.             dcl t1.xy
  456.             dcl t2.xy
  457.             dcl t3.x
  458.             dcl t4.xy
  459.             dcl v0.rgba
  460.  
  461.             dcl_2d s0
  462.             dcl_2d s1
  463.             dcl_2d s2
  464.             dcl_2d s3
  465.             
  466.             texld   r10, t1, s1            // Z - semplovani Z projektovane teksture
  467.             sub     r9.r, r10.r, t3.x   // razlika Z vrednosti
  468.  
  469.             mov     r1, c1              // r1 - 1, 1, 1, 1
  470.             cmp     r10, r9.r, c0, r1   //-r9.r//, r1
  471.  
  472.             texld   r1, t0, s0
  473.             mad     r0, r10, v0, c17    // (shadow * diffuse) + ambient
  474.             
  475.             texld   r2, t4, s3  // r2 = burn texture
  476.             lrp     r3, r2.a, r1, r2
  477.             lrp     r2, c16.x, r1, r3
  478.             
  479.             mul     r0, r2, r0
  480.  
  481.             texld   r2, t2, s2
  482.             mul     r0, r2, r0
  483.  
  484. //            add_sat r0, r0, c15
  485.             
  486.             mov     r0.a, r1.a
  487.             mov     oC0, r0                // output
  488.         };
  489.     }
  490. }
  491.  
  492.  
  493. // rendering u shadow mapu
  494. technique Technique5
  495. {
  496.     pass Pass0
  497.     {
  498.         Texture[0]               = (DiffuseTexture);
  499.  
  500.         VertexShaderConstant[0]   = <WorldViewProjection>;
  501.         VertexShaderConstant[31]  = <ZBias>;
  502.  
  503.         ALPHABLENDENABLE = TRUE;
  504.         SRCBLEND         = SRCALPHA;
  505.         DESTBLEND        = INVSRCALPHA;
  506.         ALPHATESTENABLE  = TRUE;
  507.         ALPHAFUNC        = GREATER;
  508.         ALPHAREF         = 1;
  509.  
  510.         VertexShader =
  511.         decl
  512.         {
  513.             stream 0;
  514.             float v0[3];       // Position
  515.             float v3[3];       // Normal
  516.             float v6[2];       // Texture coord1
  517.         }
  518.         asm
  519.         {
  520.             //-----------------------------------------------------------------------------
  521.             // Vertex shader for rendering shadows
  522.             // c0..3    - WVP
  523.             // c4..7    - world to light proj x-form
  524.             // c8..11    - shadow proj x-form
  525.             // c12.13    - View matrix
  526.             // c30        - light direction
  527.             // c31        - Z Bias vector
  528.             //-----------------------------------------------------------------------------
  529.             vs_1_1
  530.  
  531.             dcl_position   v0
  532.             dcl_texcoord0  v6
  533.         
  534.             m4x4  r0, v0, c0   // Transform position
  535.             mov   oPos, r0     // Output position
  536.             mov   oT0, v6
  537.             mov   oT1.x, r0.z  // Output depth
  538.             
  539.         };
  540.         
  541.         PixelShader =
  542.         asm
  543.         {
  544.             ps_1_4
  545.  
  546.             // Incoming depth
  547.             dcl        t0.xyzw
  548.             dcl        t1.x
  549.             dcl_2d  s0
  550.             
  551.             texld   r1, t0, s0
  552.             mov        r0, t1.x
  553.             mov     r0.w, r1.w
  554.             mov        oC0, r0
  555.         };
  556.     }
  557. }
  558.